package example.array;

import java.util.ArrayList;

/**
 * Created by lenovo on 2016/11/4 0004.
 * retainAll()计算两个数组交集
 */
public class Intersection {
    public static void main(String[] args) {
        ArrayList<String> array = new ArrayList<String>();
        array.add(0, "A");
        array.add(1, "C");
        array.add(2, "E");
        ArrayList<String> array2 = new ArrayList<>();
        array2.add(0, "A");
        array2.add(1, "B");
        array2.add(2, "C");
        array2.add(3, "D");
        System.out.println("array1 数组元素：" + array);
        System.out.println("array2 数组元素：" + array2);
        array.retainAll(array2);
        System.out.println("array2 & array1 数组交集为：" + array);
    }
}
